package com.liao.seckill.controller;

import com.alibaba.fastjson.JSON;
import com.liao.seckill.constant.OrderConstant;
import com.liao.seckill.pojo.TbMiaoshaOrder;
import com.liao.seckill.pojo.TbOrderInf;
import com.liao.seckill.pojo.TbUser;
import com.liao.seckill.result.Result;
import com.liao.seckill.result.ResultCode;
import com.liao.seckill.service.GoodsMiaoshaService;
import com.liao.seckill.service.OrderService;
import com.liao.seckill.service.UserService;
import com.liao.seckill.vo.ResOrderDetail;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/order")
public class OrderController {

    private final OrderService orderService;
    private final StringRedisTemplate redisTemplate;

    public OrderController(OrderService orderService,StringRedisTemplate redisTemplate) {
        this.orderService = orderService;
        this.redisTemplate = redisTemplate;
    }

    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ResponseBody
    public Result<Object> detail(String orderId) {
        TbOrderInf tbOrderInf = orderService.findById(orderId);
        if (tbOrderInf == null) {
            return new Result<>(ResultCode.ORDER_NOTFOUND);
        }
        TbMiaoshaOrder tbMiaoshaOrder = orderService.findMiaoShaOrderByOrderId(orderId);
        ResOrderDetail resOrderDetail = new ResOrderDetail();
        resOrderDetail.setMiaoshaOrder(tbMiaoshaOrder);
        resOrderDetail.setOrderInf(tbOrderInf);
        return new Result<>(resOrderDetail);
    }
}
